package sprite;

import java.awt.geom.AffineTransform;


public class Transform {
	private double _x;
	private double _y;

	private AffineTransform _at;
	private AffineTransform _rat;
	
	private double _cx;
	private double _cy;

	private boolean _isPivotRight = true;

	public Transform(){
		_rat = new AffineTransform();
		_x = 0;
		_y = 0;
	}
	

	public void translate(double x,double y){
		_at = new AffineTransform();
		_at.translate(_cx,_cy);
		_at.translate(x, y);
		_at.translate(-_cx,-_cy);
		_rat.preConcatenate(_at);
		_x += x;
		_y += y;
	}
	

	public void scale(double xscl,double yscl){
		_rat.translate(_cx,_cy);
		_rat.scale(xscl,yscl);
		_rat.translate(-_cx,-_cy);
	}

	public void flip(){
		_rat.translate(_cx,_cy);
		_rat.scale(-1,1);
		_rat.translate(-_cx,-_cy);
		_isPivotRight = !_isPivotRight;

	}

	public double getX(){
		return _x+_cx;
	}
	

	public double getY(){
		return _y+_cy;
	}
	
	public AffineTransform getTransform(){
		return _rat;
	}
	
	public void setOrigin(int x, int y){
		_cx = x;
		_cy = y;
	}
	public int getOriginX(){
		return (int)Math.round(_cx);
	}

	public int getOriginY(){
		return (int)Math.round(_cy);
	}

	public boolean isFlippedRight(){
		return _isPivotRight;
	}
}

